package com.honeywell.util;

import com.honeywell.entity.Result;

/**
 * @author: mabingbing 
 * @createDate: 2018年4月18日 上午11:31:19
 * @email: mabingbing@hiynn.com
 * @since:
 * @descript: 返回结果Builder工具
 */
public class ResultBuilder {
	
	private static final int SUCCESS_CODE = 0;
	private static final String SUCCESS_MSG = "接口调用成功!";
	private static final int FAIL_CODE = 1;
	private static final String FAIL_MSG = "接口调用失败!";
	private static final int UNAUTHENTIED_CODE = 2;
	private static final String UNAUTHENTIED_MSG = "没有登录!";
	private static final int UNAUTHORIZED = 3;
	private static final String UNAUTHORIZED_MSG = "无权限!";
	
	public static Result success(){
		return success(SUCCESS_MSG);
	}
	
	
	/**
	 * @param msg 提示信息
	 * @return   Result  
	 * @descript   
	 */
	public static Result success(String msg){	
		return success(msg, null);		
	}	
	/**
	 * @param data 返回的数据result部分
	 * @return     Result   
	 * @descript
	 */
	public static Result success(Object data){
		Result result = new Result(SUCCESS_CODE, SUCCESS_MSG);
		result.setResult(data);
		return result;
	}
	
	/**
	 * @param msg 调用成功提示信息
	 * @param data   数据部分
	 * @return     
	 * @descript
	 */
	public static Result success(String msg, Object data){
		Result result = new Result(SUCCESS_CODE, msg);
		result.setResult(data);
		return result;
	}
	
	
	public static Result fail(){
		return fail(FAIL_MSG);
	}
	
	/**
	 * @param msg失败提示信息
	 * @return    Result 
	 * @descript
	 */
	public static Result fail(String msg){	
		return fail(msg, null);		
	}
	
	public static Result fail(String msg, Object data){
		Result result = new Result(FAIL_CODE, msg);
		result.setResult(data);
		return result;
	}
	
	/**没有登录返回的错误信息--begin*/
	public static Result unAuthentied(){
		return unAuthentied(UNAUTHENTIED_MSG);
	}
	
	/**
	 * @param msg 没有登录提示信息
	 * @return   Result  
	 * @descript
	 */
	public static Result unAuthentied(String msg){	
		return unAuthentied(msg, null);		
	}	
	public static Result unAuthentied(String msg, Object data){
		Result result = new Result(UNAUTHENTIED_CODE, msg);
		result.setResult(data);
		return result;
	}	
	/**没有登录返回的错误信息--end*/
	
	
	/**无权限返回的错误信息--begin*/
	public static Result unAuthorized(){
		return unAuthorized(UNAUTHORIZED_MSG);
	}
	
	/**
	 * @param msg 认证失败提示信息
	 * @return   Result  
	 * @descript
	 */
	public static Result unAuthorized(String msg){	
		return unAuthorized(msg, null);		
	}
	public static Result unAuthorized(String msg, Object data){
		Result result = new Result(UNAUTHORIZED, msg);
		result.setResult(data);
		return result;
	}	
	/**无权限返回的错误信息--end*/
}
